package com.flowerSystem.interceptor;

import com.flowerSystem.util.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局处理控制器里的异常
 */
@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(NoLoginException.class)
    public ResponseResult exceptionHandler(NoLoginException ex) {
        ResponseResult result = new ResponseResult();
        result.setCode(ex.getCode());
        result.setMessage(ex.getMessage());
        return result;
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHandler(Exception ex) {
        log.error("系统错误：{}",ex.getMessage());
        ResponseResult result = new ResponseResult();
        result.setCode(500);
        result.setMessage(ex.getMessage());
        return result;
    }
}
